package vincent.com.layouttest.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import vincent.com.layouttest.util.LogUtil;

/**
 * Created by zvin-chen on 17/2/27.
 * 测试类，暂时无实际用途
 */

public class BroadcastImpl implements Parcelable{
    public String descriptor = null;

    private static BroadcastImpl instance;

    private BroadcastImpl remoteInstance;

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(descriptor);
        dest.writeParcelable(remoteInstance, flags);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<BroadcastImpl> CREATOR = new Creator<BroadcastImpl>() {
        @Override
        public BroadcastImpl createFromParcel(Parcel in) {
            return new BroadcastImpl(in);
        }

        @Override
        public BroadcastImpl[] newArray(int size) {
            return new BroadcastImpl[size];
        }
    };

    public void setRemoteInstance(BroadcastImpl impl){
        this.remoteInstance = impl;
    }

    public BroadcastImpl getRemoteInstance(){
        return this.remoteInstance;
    }

    protected BroadcastImpl(Parcel in) {
        descriptor = in.readString();
        remoteInstance = in.readParcelable(BroadcastImpl.class.getClassLoader());
    }

    public static BroadcastImpl getInstance(String descriptor){
        if(instance == null){
            instance = new BroadcastImpl(descriptor);
        }else if(!descriptor.equals(instance.descriptor)){
            throw new RuntimeException("wrong fuck call parameter");
        }

        return instance;
    }

    private BroadcastImpl(String descriptor){
        this.descriptor = descriptor;
    }

    public void fuck(){
        LogUtil.i("czw", this.descriptor + "----> oh fuck");
    }
}
